package feed;

import javax.microedition.lcdui.Graphics;

import skeleton.ElePet;
import skeleton.View;

public class FeedView implements View {

	ElePet elepet;
	
	public FeedView(ElePet e) {
		elepet = e;
	}
	
	public void doPaint(Graphics g) {
		if (elepet.state != ElePet.FEED_MENU) return;
		elepet.hadType.setChoose(elepet.chose);
		elepet.hadType.paint(g);
		elepet.hadAmount.setChoose(-1);
		elepet.hadAmount.paint(g);
	}

	public void keyPressed(int theKey) {
		if (elepet.state != ElePet.FEED_MENU) return;
		switch (theKey) {
		case ElePet.DOWN:
			if (elepet.chose < elepet.hadType.size()-1) ++elepet.chose;
			break;
		case ElePet.LEFT:
			elepet.state = ElePet.MAIN_MENU;
			elepet.chose = elepet.choseRecord[ElePet.MAIN_MENU];
			break;
		case ElePet.UP:
			if (elepet.chose > 1) --elepet.chose;
			break;
		case ElePet.FIRE:
			select();
			break;
		}
	}
	
	private void select() {
		String selName = elepet.myItem.getName(elepet.chose-1);
		if (elepet.myItem.getAmount(selName) > 0) {
			elepet.myItem.minus(selName);
			elepet.hadAmount.modify(
					elepet.chose, "x " + elepet.myItem.getAmount(selName));
		}
	}

}
